<?php
/**
 * Created by PhpStorm.
 * User: poptser@foxmail.com
 * Date: 2018/4/21
 * Time: 14:33
 */

namespace App\Http\Controllers\Sorting;

use App\Http\Controllers\ApiController;
use App\Services\Sorting\SortingService;
use App\Services\SortingWeb\ToolService;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;


class BaseController extends ApiController
{

    public $sortingService;
    public $toolService;    //辅助工具 service

    public $userId;
    public $wid;

    public function __construct(SortingService $sortingService,
                                ToolService $toolService)
    {
        $isLogion = Auth::guard('sorting')->check();
        if (!$isLogion) {
            $this->returnErr("api_token 不存在或已过期");
        } else {
            $this->userId = Auth::guard('sorting')->id();
            if ($this->checkUserType(8, $this->userId)) {
                //$this->returnErr("您没有访问此接口得权限");
            }
        }
        $this->toolService = $toolService;
        $this->sortingService = $sortingService;
        $this->wid = $this->toolService->getUserWid($this->userId);
    }

    /**
     * 提交拣货单异常商品
     * Author:poptser@foxmail.com
     * @param Request $request
     * @return mixed
     */
    public function setSortingOrderOdd(Request $request){
        $goodDate = json_decode($request->goodDate,true);
        if(!empty($goodDate)){
            //return $goodDate;
            $judgment = $this->sortingService->setSortingOrderOdd($goodDate,$this->userId);
            if($judgment===true){
                return $this->success(null,"已完成");
            }else{
                return $this->failedReturn($judgment);
            }
        }else{
            return $this->failedReturn("json 数据异常");
        }
    }
}